package org.dtrd.modules.patient.entity.bean.report;

import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.dtrd.common.util.DateUtils;
import org.dtrd.config.system.Constant;
import org.dtrd.modules.patient.entity.po.DtrdEntRdReport;
import org.dtrd.modules.record.entity.bean.PeriodBloodPressure;
import org.dtrd.modules.record.entity.bean.PeriodBmi;
import org.dtrd.modules.record.entity.bean.SugarChart;

import java.util.Date;
import java.util.List;

/**
 * @author : qiannai
 * @date: 2022/8/19 9:51
 * @describe : 生成月报
 */
@ApiModel("月报返回格式")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class ReportMonth {

    @ApiModelProperty("报告的id")
    private Integer dataId;

    @ApiModelProperty("报告名字")
    private String reportName;

    @ApiModelProperty("报告创建时间")
    @JsonFormat(pattern = Constant.TIME_PATTERN_SDF, timezone = Constant.TIME_ZONE_1)
    private Date reportCreateTime;

    @ApiModelProperty("报告编号")
    private String reportId;

    @ApiModelProperty("患者姓名")
    private String patientsName;

    @ApiModelProperty("患者性别")
    private String patientsSex;

    @ApiModelProperty("患者年龄")
    private Integer patientAge;

    @ApiModelProperty("月报数据")
    public MonthReportContent reportContent = new MonthReportContent();

    @ApiModelProperty("月报输入数据")
    public ReportMonthUpdateRequest.ReportMonthInputUpdate monthInputUpdate = new ReportMonthUpdateRequest.ReportMonthInputUpdate();

    @ApiModelProperty("总结")
    private String summary;

    @ApiModelProperty("发布状态")
    private Integer publishStatus;

    @ApiModelProperty("制表人")
    private String creator;

    public ReportMonth parseFromPo(DtrdEntRdReport po) {
        this.dataId = po.getDataId();
        this.reportName = po.getReportName();
        this.reportCreateTime = po.getCreateTime();
        this.reportId = DateUtils.date2Str(po.getCreateTime(),DateUtils.short_date_sdf_ym.get()) + po.getDataId().toString();
        this.patientsName = JSONUtil.toBean(po.getPatientArchive(), MonthReportContent.class).getBasicInfo().getPatientsName();
        this.patientsSex = JSONUtil.toBean(po.getPatientArchive(), MonthReportContent.class).getBasicInfo().getPatientsSex();
        this.patientAge = JSONUtil.toBean(po.getPatientArchive(), MonthReportContent.class).getBasicInfo().getPatientAge();
        this.reportContent = JSONUtil.toBean(po.getPatientArchive(), MonthReportContent.class);
        this.monthInputUpdate = JSONUtil.toBean(po.getPatientArchiveReport(), ReportMonthUpdateRequest.ReportMonthInputUpdate.class);
        this.summary = po.getSummary();
        this.publishStatus = po.getPublishStatus();
        return this;
    }

    @ApiModel("月报数据")
    @Getter
    @Setter
    public static class MonthReportContent {

        @ApiModelProperty("基本信息")
        private PatientBasicInfo basicInfo;

        @ApiModelProperty("服务方案")
        private ReportServiceProgramme serviceProgramme;

//        @ApiModelProperty("控制目标内容-已弃用")
//        private ReportTable targets;

        @ApiModelProperty("每日打卡计划")
        private ReportTable dailySigninRecords;

        @ApiModelProperty("周打卡率")
        private String weeklySigninRate;

        @ApiModelProperty("建议内容")
        private ReportWeekSuggest suggests;

        @ApiModelProperty("血糖图表数据")
        private SugarChart sugarChart;

        @ApiModelProperty("血压图表数据")
        private PeriodBloodPressure periodBloodPressure;

        @ApiModelProperty("体重图表数据")
        private PeriodBmi periodBmi;

        @ApiModelProperty("控制目标新")
        private List<ControllerTargetReport> controllerTargetReportList;

        @ApiModelProperty("打卡率和达标率")
        private SigninRateLine signinRateLine;

    }
}
